//
//  DetailsViewController.m
//  Travel
//
//  Created by lanou3g on 15/12/9.
//  Copyright © 2015年 涂晓雨. All rights reserved.
//

#import "DetailsViewController.h"
#import "CX_DataDownloadTools.h"
#import "DetailsModel.h"
@interface DetailsViewController ()<UIWebViewDelegate>

@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation DetailsViewController

-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray new];
    }
    return _dataArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"听说";
    //设置左barbutton
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont.png"] style:UIBarButtonItemStyleDone target:self action:@selector(actionLeft:)];
    
    self.DetailsWebView = [[UIWebView alloc]initWithFrame:self.view.bounds];
    self.DetailsWebView.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:self.DetailsWebView];
    self.DetailsWebView.delegate = self;
    
//    NSString *str = [NSString stringWithFormat:@"%ld",(long)self.model.Id];
    
    [CX_DataDownloadTools downloadDataWithURL:@"http://webapi.yilule.com:5580//api/Listen?listenId=46464488-c4d9-47eb-a629-98c2ac553151" andMethod:@"GET" andBody:nil andBlock:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
          NSDictionary *dict = dic[@"Data"];
        NSDictionary *dics = dict[@"ReviewList"];
        NSArray *arr = dics[@"Reviews"];
        for (NSDictionary *dicss in arr) {
            DetailsModel *m = [[DetailsModel alloc]init];
            [m setValuesForKeysWithDictionary:dicss];
            [self.dataArray addObject:m];
            NSLog(@"%@--%@",dict,arr);

        }
        NSMutableString *str = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        [self.DetailsWebView loadHTMLString:str baseURL:nil];
    }];

}
//左barbutton监听
- (void)actionLeft:(UIBarButtonItem *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
